{% extends 'base.html' %}

{% block content %}
<p>{{ movies|length }} Titles - {{ res.pages}} Pages</p>
{# % if current_user.is_authenticated % #}
    <form method="post">
        <label for="name">名字</label>
        <input type="text" name="title" autocomplete="off" required>
        <label for="year">年份</label>
        <input type="text" name="year" autocomplete="off" required>
        <input class="btn" type="submit" name="submit" value="Add">
    </form>
{# % endif % #}
<div class="header-paginate">
    <button onclick="window.location.href='index?page=1'">分页显示</button>
    <button onclick="window.location.href='index'">全部显示</button>
</div>
<br/>

<ul class="movie-list">
    {% for movie in res.items %}
    <li>{{ movie.title }} - {{ movie.year }}
        <span class="float-right">
            <a class="btn" href="{{ url_for('edit', movie_id=movie.id) }}">Edit</a>
            <form class="inline-form" method="post" action="{{ url_for('delete', movie_id=movie.id) }}">
                <input class="btn" type="submit" name="delete" value="Delete" onclick="return confirm('Are you sure?')">
            </form>
            <a class="imdb" href="https://www.imdb.com/find?q={{ movie.title }}" target="_blank" title="Find this movie on IMDb">IMDb</a>
        </span>
    </li>
    {% endfor %}
</ul>
<nav class="paginate">
    <nav >
    {% if res.has_prev %}
        <button onclick="window.location.href='index?page={{ res.prev_num }}'">上一页</button>
    {% endif %}

        <button>第{{ res.page }}页</button>

    {% if res.has_next and res.page < 5 %}
        <button onclick="window.location.href='index?page={{ res.next_num }}'">下一页</button>
    {% else %}
        <button>最后一页</button>
    {% endif %}

    <nav class="first-last-page">
        <button onclick="window.location.href='index?page=1'">首页</button>
        <button onclick="window.location.href='index?page={{ res.pages}}'">尾页</button>
        <button onclick="window.location.href='index'">全部显示</button>
    </nav>
    </nav>


</nav>


{% endblock %}